//
//  NSString+Size.m
//  DDKelai
//
//  Created by nianfangge on 15/7/29.
//  Copyright (c) 2015年 chenwenhao. All rights reserved.
//

#import "NSString+Size.h"

@implementation NSString (Size)

- (CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize
{
    if (IOS7)
    {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        
        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
        NSDictionary *attributes = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle.copy};
        
        return [self boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading  attributes:attributes context:nil].size;
        
        return  CGSizeZero;
    }else{
       return [self sizeWithFont:font constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
    }
}



-(float)heightWithFontSize:(float)fontSize andWidth:(float)width
{
    if (IOS7){
        UIFont *font =[UIFont systemFontOfSize:fontSize];
        NSDictionary *attrs = @{NSFontAttributeName : font};
       CGSize result=[self boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attrs context:nil].size;
        return result.height;
      
    }else{
        UIFont *font =[UIFont systemFontOfSize:fontSize];
        CGSize result=[self sizeWithFont:font constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
        return result.height;
    }
}


@end
